package com.ww.learn.generic

open class Fruit
class Banana : Fruit()
class Orange : Fruit()

//fun receiveFruits(fruits: Array<Fruit>) {
//    println("Number of fruits: ${fruits.size}")
//}

fun receiveFruits(fruits: List<Fruit>) {
    println("Number of fruits: ${fruits.size}")
}

fun main() {
//    val bananas: Array<Banana> = arrayOf()
    // 像Java一样不允许传入子类型
    // Type mismatch.
    //Required:
    //Array<Fruit>
    //Found:
    //Array<Banana>
//    receiveFruits(bananas)

    // 分析为什么Array<Banana>报错，而List<Banana>却ok
    // 这是因为：Array<T>是可变的，而List<T>是不可变的
    val bananas: List<Banana> = listOf()
    receiveFruits(bananas) // OK
}